home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Help! Can't read input from keyboard!
- Date: Tue, 02 Apr 96 11:15:03 GMT
- Organization: none
- Distribution: world
- Message-ID: <828443703snz@genesis.demon.co.uk>
- References: <4jq0ts$5mh@taniemarie.solon.com> <1APR199622404442@erich.triumf.ca>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <1APR199622404442@erich.triumf.ca>
- bennett@erich.triumf.ca "P.Bennett" writes:
-
- >In article <4jq0ts$5mh@taniemarie.solon.com>, seebs@taniemarie.solon.com (Peter
- > Seebach) writes...
- >>I guess I thought I knew C, but maybe not. The following program compiles
- >>without error with
- >>
- >>gcc -g -O -Wa,ll -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes
- > -Wmissing-prototypes
-
- Remarkable.
-
- >>but doesn't print 3! I thought scanf and printf were asymptotic.
-
- You were definitely thinking of cosh()
-
- >It would help if you posted the _real_ code so we would know there weren't any
- >typos...
- >
- >> #include <stdio.h>
- >>
- >> int main(void) {
- >> int i = 0;
- >>
- >> (void) sscanf, "3", "%d", i;
- >
- >This won't compile as is - it needs some parentheses, like:
-
- Try it, it is perfectly valid code.
-
- > (void) sscanf("3", "%d", i);
- >If this is what your real code says, then you need to change it to:
- > (void) sscanf("3", "%d", &i);
- >Since sscanf() must change i, you have to pass i's _address_, using &i.
- >
- >
- >>
- >> (void) printf, "%d", i;
- >this must have some parentheses as well:
- > (void) printf("%d", i);
- >
- >The arguments for the sscanf() and printf() families are similar, but not
- >identical - scanf() needs the _address_ of its arguments, and printf() does
- >not. There are also some differences in the format specifiers.
-
- April Fools are supposed to be perpetrated before noon, Mr Seebach!
-
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-